#ifndef NODECONTROLLERTASK_H
#define NODECONTROLLERTASK_H

#include <QRunnable>
#include <QObject>
#include <QTcpSocket>
#include <QMutex>
#include <QMap>
#include <QThread>

class NodeControllerTask : public QObject, public QRunnable
{
    Q_OBJECT

public:
    NodeControllerTask(int nodeId, const QString& host, int port, QObject* parent = nullptr);
    ~NodeControllerTask();

    void run() override;

signals:
    void dataReady(int nodeId, const QString& data);

private slots:
    void onConnected();
    void onDisconnected();
    void onReadData();
    void onHandleError(QAbstractSocket::SocketError error);
    void onTimeout();

private:
    int nodeId;
    QString host;
    int port;
    QTcpSocket* socket;  // 独立的 QTcpSocket 对象
    bool isConnected = false;  // 标记是否已连接成功
};

#endif // NODECONTROLLERTASK_H
